#include <windows.h>
#include <windowsx.h>
#include <string.h>
#include "splshapi.h"
#include "errorapi.h"

FARPROC pfnSplashInit;
FARPROC pfnSplashExecute;
HINSTANCE hLibrary;

BOOL WINAPI IntelSplashInit()
{
	int iErr;

	//
	// Dynamically load the SPLASH DLL and execute the
	// two functions SplashInit() and SplashExecute()
	//
#if WIN16
	hLibrary = LoadLibrary( "SPLASH16.DLL" );
#endif
#if WIN32
	hLibrary = LoadLibrary( "SPLASH32.DLL" );
#endif
	if ( (int)hLibrary < HINSTANCE_ERROR )
	{
		//MessageBox( 0, "Could not find Splash DLL", "Error", MB_OK );
		OutputDebugString( "Could not find Splash DLL\n" );
		return FALSE;
	}
#if WIN16
	pfnSplashInit = GetProcAddress( hLibrary, "SplashInit" );
#endif
#if WIN32
	pfnSplashInit = GetProcAddress( hLibrary, "_SplashInit@4" );
#endif
	if ( !pfnSplashInit )
	{
		OutputDebugString( "Invalid Splash DLL\n" );
		return FALSE;
	}
#if WIN16
	pfnSplashExecute = GetProcAddress( hLibrary, "SplashExecute" );
#endif
#if WIN32
	pfnSplashExecute = GetProcAddress( hLibrary, "_SplashExecute@0" );
#endif
	if ( !pfnSplashExecute )
	{
		OutputDebugString( "Invalid Splash DLL\n" );
		return FALSE;
	}

	//
	// Initialize the Splash DLL indicating the language to display
	//
	iErr = pfnSplashInit( (DWORD)SPLASH_LANG_ENGLISH );
	if ( iErr ){
		OutputDebugString( "An error occurred initializing the Splash DLL.\n" );
		return FALSE;
	}

	return TRUE;
}

BOOL WINAPI IntelSplash()
{
int iErr;

	//
	// Execute Splash screen
	//
	iErr = pfnSplashExecute();
	if ( iErr ){
		OutputDebugString( "An error occurred executing the Splash screen." );
		return FALSE;
	}
	return TRUE;
}
